package com.okyai.kt.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.okyai.common.annotation.Log;
import com.okyai.common.enums.BusinessType;
import com.okyai.kt.domain.TopicItem;
import com.okyai.kt.service.ITopicItemService;
import com.okyai.common.core.controller.BaseController;
import com.okyai.common.core.domain.AjaxResult;
import com.okyai.common.utils.poi.ExcelUtil;
import com.okyai.common.core.page.TableDataInfo;

/**
 * 课题项目Controller
 * 
 * @author okyai
 * @date 2021-03-20
 */
@Controller
@RequestMapping("/kt/topic/item")
public class TopicItemController extends BaseController
{
    private String prefix = "kt/topic/item";

    @Autowired
    private ITopicItemService topicItemService;

    @RequiresPermissions("kt:item:view")
    @GetMapping()
    public String item()
    {
        return prefix + "/item";
    }

    /**
     * 查询课题项目列表
     */
    @RequiresPermissions("kt:item:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TopicItem topicItem)
    {
        startPage();
        List<TopicItem> list = topicItemService.selectTopicItemList(topicItem);
        return getDataTable(list);
    }

    /**
     * 导出课题项目列表
     */
    @RequiresPermissions("kt:item:export")
    @Log(title = "课题项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TopicItem topicItem)
    {
        List<TopicItem> list = topicItemService.selectTopicItemList(topicItem);
        ExcelUtil<TopicItem> util = new ExcelUtil<TopicItem>(TopicItem.class);
        return util.exportExcel(list, "item");
    }

    /**
     * 新增课题项目
     */
    @GetMapping("/add/{topicId}")
    public String add(@PathVariable("topicId") Long topicId, ModelMap mmap)
    {
    	mmap.put("topicId", topicId);
        return prefix + "/add";
    }

    /**
     * 新增保存课题项目
     */
    @RequiresPermissions("kt:item:add")
    @Log(title = "课题项目", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TopicItem topicItem)
    {
        return toAjax(topicItemService.insertTopicItem(topicItem));
    }

    /**
     * 修改课题项目
     */
    @GetMapping("/edit/{topicItemId}")
    public String edit(@PathVariable("topicItemId") Long topicItemId, ModelMap mmap)
    {
        TopicItem topicItem = topicItemService.selectTopicItemById(topicItemId);
        mmap.put("topicItem", topicItem);
        return prefix + "/edit";
    }

    /**
     * 修改保存课题项目
     */
    @RequiresPermissions("kt:item:edit")
    @Log(title = "课题项目", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TopicItem topicItem)
    {
        return toAjax(topicItemService.updateTopicItem(topicItem));
    }

    /**
     * 删除课题项目
     */
    @RequiresPermissions("kt:item:remove")
    @Log(title = "课题项目", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(topicItemService.deleteTopicItemByIds(ids));
    }
    
}
